package ar.com.cooker.services.uow.ingredient;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import ar.com.cooker.dao.IngredientDao;
import ar.com.cooker.model.Ingredient;
import ar.com.cooker.services.pojo.IngredientPojo;
import ar.com.cooker.services.uow.GetAllUOW;
import ar.com.cooker.services.util.ConvertBOtoPojo;

public class GetAllIngredientUOW implements GetAllUOW<IngredientPojo>{

	@Autowired
	private IngredientDao ingredientDao;
	
	@Override
	public IngredientPojo[] execute() {
		
		IngredientPojo[] ingredientPojos = null;
		int cant = 0;
		List<Ingredient> ingredients = getIngredientDao().findAll();
		ingredientPojos = new IngredientPojo[ingredients.size()];
		for(Ingredient i : ingredients){
			ingredientPojos[cant] = ConvertBOtoPojo.getIngredientPojoToIngredient(i);
			cant++;
		}
		return ingredientPojos;
	}

	public void setIngredientDao(IngredientDao ingredientDao) {
		this.ingredientDao = ingredientDao;
	}

	public IngredientDao getIngredientDao() {
		return ingredientDao;
	}

}
